package com.lin.cloud.disk.config;

import com.alipay.easysdk.factory.Factory;
import com.alipay.easysdk.kernel.Config;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.io.Serializable;

/**
 * @program: cloud-disk
 * @description:
 * @author: Lin
 * @create: 2021-03-10 23:35
 **/
@Slf4j
@Component
public class AlipayConfig implements ApplicationRunner {
    @Value("${alipay.appId}")
    private String appId;
    @Value("${alipay.merPrivateKey}")
    private String privateKey;
    @Value("${alipay.alipayPublicKey}")
    private String publicKey;
    @Value("${alipay.gateway}")
    private String gateway;
    @Value("${alipay.notifyUrl}")
    private String notifyUrl;
    @Override
    public void run(ApplicationArguments args){
        Factory.setOptions(getOptions());
        log.warn("==================================支付宝SDK初始化完成");
    }
    private Config getOptions() {
        Config config = new Config();
        config.protocol = "https";
        config.gatewayHost = this.gateway;
        config.signType = "RSA2";
        config.appId = this.appId;
        config.merchantPrivateKey = this.privateKey;
        config.alipayPublicKey = this.publicKey;
        config.notifyUrl = notifyUrl;
        return config;
    }
}